/**
 * @Author: YLTDMenglc
 * @Date: 2019/11/29
 * @Time: 14:20
 * @Description:2N个元素数组两两随机分组
 */
function arrSlice(arr) {
    if(arr.length % 2 !== 0) return 0;
    var newArr = [],tmpArr = []; //临时辅助数组
    for(var i=0;i<arr.length;i++) {
        if(!tmpArr.includes(arr[i])) {
            var rndIndex;
            do {
                rndIndex = Math.floor(Math.random() * (arr.length - (i + 1))) + (i + 1);
            } while(tmpArr.includes(arr[rndIndex]));
            newArr.push([arr[i],arr[rndIndex]]);
            tmpArr.push(arr[i]);
            tmpArr.push(arr[rndIndex]);
        }
    }
    return newArr;
}
var arr = [1,2,3,4,5,6,7,8]
console.log(arrSlice(arr));